package main

import "fmt"

func main() {
	friends := make(map[string][]string)
	friends["me"] = []string{"one", "two", "three", "four"}
	friends["one"] = []string{"me", "apple", "phone"}
	friends["two"] = []string{"me"}
	friends["three"] = []string{"me"}
	friends["four"] = []string{"me", "pc", "banana"}

	//维护一个队列，每次检查左边的第一个，新的朋友就附加到队列的右侧
	var searchs []string

	isChecked := make(map[string]*struct{})
	searchs = append(searchs, "me")
	for len(searchs) > 0 {
		//从队列的左边切一个数据出来做检查
		check := searchs[0]
		searchs = searchs[1:]
		if _, ok := isChecked[check]; !ok {
			//把检查的数据加入检查的列表
			isChecked[check] = &struct{}{}
			if isBanana(check) {
				fmt.Println("找到了banana")
			} else {
				//把没有找到的朋友加入队列
				searchs = append(searchs, friends[check]...)
			}
		}

	}

}

func isBanana(name string) bool {
	if name == "banana" {
		return true
	}

	return false
}
